package cn.smbms.controller;

import cn.smbms.pojo.Bill;
import cn.smbms.pojo.Provider;
import cn.smbms.service.bill.BillService;
import cn.smbms.service.provider.ProviderService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/Bill")
public class BillController {

    @Resource
    private BillService billService;
    @Resource
    private ProviderService providerService;
    @RequestMapping(value = "billlist.html", method = RequestMethod.GET)
    public String getBillList(Model model, @RequestParam(value = "productName", required = false) String productName,
                              @RequestParam(value = "providerId", required = false) Integer providerId,
                              @RequestParam(value = "isPayment", required = false) Integer isPayment) {
        List<Bill> list = null;
        List<Provider> list2 = null;
        if (productName == null) {
            productName = "";
        } else {
            productName = "%" + productName + "%";
        }
            Bill bill = new Bill();
            bill.setProductName(productName);
            bill.setProviderId(providerId);
            bill.setIsPayment(isPayment);
            list = billService.getBillList(bill);
            list2 = (List<Provider>) providerService.getProviderById(providerId);
            model.addAttribute("providerList", list2);
            model.addAttribute("billList", list);
            return "billlist";
        }
}
